package com.yang.cannal;
import com.alibaba.otter.canal.protocol.CanalEntry;
import com.xpand.starter.canal.annotation.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 监听店铺表的信息改变，保证数据库和缓存的一致性
 * </p>
 * @author yang
 * @date 2023/8/24
 */
@CanalEventListener
public class ShopDataBinLog {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Resource
    private RabbitTemplate rabbitTemplate;

    @UpdateListenPoint(schema = "hmdp",table = "tb_shop")
    public void shopUpdateListening(CanalEntry.EventType eventType, CanalEntry.RowData rowData){
        // todo
        // 获取修改的店铺信息
        // 将店铺信息发送消息队列
        // 消费者获取消息，删除redis的缓存，删除成功ack，删除失败重试，多次失败转人工
        // 缓存设置时间兜底
        List<CanalEntry.Column> beforeColumnsList = rowData.getBeforeColumnsList();
        System.out.println(beforeColumnsList);
    }

    @DeleteListenPoint(schema = "hmdp",table = "tb_shop")
    public void shopRemoveListening(CanalEntry.EventType eventType, CanalEntry.RowData rowData){
        // todo
    }

}
